package com.cy.mall.model;

import com.cy.mall.model.enums.ResultCode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @description: 消息返回
 * @author: Ocean
 * @create: 2018-07-17 17:29
 **/
@Data
@ApiModel("消息返回")
public class Result<T> {

    @ApiModelProperty(value = "是否执行成功")
    private boolean ok;

    @ApiModelProperty(value = "返回代码")
    private String code;

    @ApiModelProperty(value = "返回信息")
    private String message;

    @ApiModelProperty(value = "返回对象")
    private T data;

    public static Result success() {
        Result result = new Result();
        result.setOk(true);
        result.setCode(ResultCode.SUCCESS.getCode());
        return result;
    }

    public static Result success(String message) {
        Result result = new Result();
        result.setOk(true);
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage(message);
        return result;
    }

    public static Result success(String message, Object value) {
        Result result = new Result();
        result.setOk(true);
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage(message);
        result.setData(value);
        return result;
    }

    public static Result success(String message, ResultCode code) {
        Result result = new Result();
        result.setOk(true);
        result.setMessage(message);
        result.setCode(code.getCode());
        return result;
    }
    
    public static Result success(String message, ResultCode code, Object value) {
    	Result result = new Result();
    	result.setOk(true);
    	result.setMessage(message);
    	result.setCode(code.getCode());
    	result.setData(value);
    	return result;
    }

    public static Result fail(String message) {
        Result result = new Result();
        result.setOk(false);
        result.setCode(ResultCode.FAIL.getCode());
        result.setMessage(message);
        return result;
    }

    public static Result fail(String message, ResultCode code) {
        Result result = new Result();
        result.setOk(false);
        result.setCode(code.getCode());
        result.setMessage(message);
        return result;
    }

    public static Result fail(String message, ResultCode code, Object value) {
        Result result = new Result();
        result.setOk(false);
        result.setCode(code.getCode());
        result.setMessage(message);
        result.setData(value);
        return result;
    }

}
